/**
 * 
 */
package com.swim.pay.web;

import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.web.BaseController;
import com.swim.pay.bean.AliPayBean;
import com.swim.pay.service.AliPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 游泳馆支付宝支付Controller
 * @author tql
 * @version 2021-08-17
 */
@Controller
@RequestMapping(value = "${adminPath}/pay/alipay")
public class SwimAliPayController extends BaseController {
	@Autowired
	private AliPayService aliPayService;


	@ResponseBody
	@RequestMapping(value = "/h5/order" )
	public String aliH5Order(AliPayBean aliPayBean, HttpServletResponse response) {
		String form = null;
		try {
			logger.info("alipay h5 order  param:{}", JSONObject.toJSONString(aliPayBean));
			form = aliPayService.aliPayH5Order(aliPayBean);
			logger.info("alipay h5 order form:{}",form);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return form;
	}


	/**
	 * 支付宝同步接口回调
	 * @param outTradeNo
	 * @return
	 * @throws Exception
	 */
	@GetMapping("/order/query")
	public String aliPayOrderQuery(String outTradeNo) throws Exception {
		logger.info("alipay order query  outTradeNo:{}", outTradeNo);
		String orderStatus = aliPayService.aliPayOrderQuery(outTradeNo);
		logger.info("alipay order query orderStatus:{}",orderStatus);
		return orderStatus;
	}
	/**
	 * 支付宝同步接口回调
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@GetMapping("/returnUrl")
	public String aliPayReturnUrl(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return aliPayService.aliPayReturnUrl(request);
	}
	/**
	 * 支付宝异步接口回调
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/notifyUrl")
	@ResponseBody
	public String aliPayNotifyUrl(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return aliPayService.aliPayNotifyUrl(request);
	}

	
}